﻿Public Class FormProduct
    Dim DA As SqlClient.SqlDataAdapter 'data adapter = use to read data from database
    Dim CB As SqlClient.SqlCommandBuilder 'comandbuilder = for create command
    Dim TBL As DataTable 'data table
    Dim rowIndex As Integer = 0

    Dim Constr As String = "Server = MASTER; Database = Testing; integrated security=sspi" 'User ID = Master\Chun Sok Chea;  'conection
    'Dim con As New SqlClient.SqlConnection(Constr)
    Private Sub FormProduct_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        DA = New SqlClient.SqlDataAdapter("Select * from tblProduct", Constr)
        TBL = New DataTable
        DA.Fill(TBL) 'transfer from DA to TBL
        If TBL.Rows.Count > 0 Then
            showData(rowIndex)
        End If
        Me.btnsave.Enabled = False
        lblCount.Text = "Record=" & rowIndex + 1 & "/" & TBL.Rows.Count
    End Sub

    Sub showData(ByVal i As Integer)
        txtcode.Text = TBL.Rows(i).Item(0)
        txttitle.Text = TBL.Rows(i).Item(1)
        txtquality.Text = TBL.Rows(i).Item(2)
        txtprice.Text = TBL.Rows(i).Item(3)
        txtdate.Text = TBL.Rows(i).Item(4)

    End Sub

End Class
